﻿using System;
using System.Collections.Generic;

using Fuse8.DomainFramework.Common;
using Fuse8.DomainFramework.Common.Locator;
using Fuse8.DomainFramework.Domain;

using Fuse8.ContentManagementFramework.Domain;
using Fuse8.ContentManagementFramework.Domain.Commands;
using Fuse8.ContentManagementFramework.Domain.Commands.CommandParameters;

namespace Fuse8.ContentManagementFramework.BizFacade.Services
{
    public class CmsWorkflowService : CmsBusinessService<CmsWorkflow, Guid>
    {
        public override CmsWorkflow FindOne(Guid id)
        {
            var command = DependencyServiceLocator.Current.GetInstance<CmsWorkflowSelectOneCommand>();

            command.ConfigureCommand(
                new CmsWorkflowSelectOneCommandParameter 
                {
                    WorkflowId = id
                });

            return FindOne(command);
        }
        
        public virtual IEnumerable<CmsWorkflow> FindAllWorkflowNotes(IEntityObject<int> entity)
        {
            Guard.ArgumentNotNull(entity, "entity");

            var command = DependencyServiceLocator.Current.GetInstance<CmsEntityGetAllWorkflowNotesCommand<CmsPage>>();

            var commandParameter = new CmsEntityGetAllWorkflowNotesCommandParameter
            {
                Id = entity.Id
            };

            SiteAwareEntityObjectMediator.SetSiteEntity(commandParameter);

            command.ConfigureCommand(commandParameter);

            return Find(command);
        }
    }
}
